<!DOCTYPE HTML>
<html>
<!--_meta 作为公共模版分离出去-->
{include file="common/_meta"}
<!--/meta 作为公共模版分离出去-->

<body>   
<article class="cl pd-20">
    <div id="tab-system" class="HuiTab">
        <div class="tabBar cl">
            <span class="step1" {eq name="step" value='1'}style="background:#5BC1FC;"{/eq}>输入新邮箱</span>
            <span class="step2" {eq name="step" value='2'}style="background:#5BC1FC;"{/eq}>输入验证码</span>
            <span class="step2" {eq name="step" value='3'}style="background:#5BC1FC;"{/eq}>修改成功</span>
        </div>
        <div class="martop" style="margin-top:60px;">
            {eq name="step" value='1'}
            <form action="" method="post" class="form form-horizontal" id="form-admin-email">
                <input type="hidden" name="step" value="{$step}">   
                <div class="tabCon tab1" style="display:block;">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>密码：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
                        </div>
                        <span class="pspan col-xs-4 col-sm-4 c-red"></span>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>新邮箱：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="text" class="input-text" autocomplete="off" value="" placeholder="请输入新邮箱" id="email" name="email">
                        </div>
                        <span class="espan col-xs-4 col-sm-4 c-red"></span>
                    </div>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-1">
                            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;发送验证码&nbsp;&nbsp;">
                            <input class="btn btn-default radius" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onClick="layer_close();">
                        </div>
                    </div>
                </div>
            </form>
            {/eq}
            {eq name="step" value='2'}
            <form action="" method="post" class="form form-horizontal" id="form-admin-token">
                    <input type="hidden" name="step" value="{$step}">   
                <div class="tabCon tab2" style="display:block;">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>请输入验证码：</label>
                    <div class="formControls col-xs-4 col-sm-3">
                        <input type="text" id="token" name="token" placeholder="请输入有效的验证码" value="" class="input-text">
                    </div>
                    <span class="col-xs-4 col-sm-2 c-red tspan"></span>
                </div>
                <div class="row cl">
                    <div class="col-xs-4 col-sm-4 col-xs-offset-2 col-sm-offset-2">
                        <input type="submit" class="btn btn-primary radius"  value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="index" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
                    </div>
                </div>
            </div>
            </form>
            {/eq}
            {eq name="step" value='3'}
            <div class="tabCon tab3" style="display:block;">
                <div class="row cl">
                    <div class=" col-xs-8 col-sm-8">
                        <p>修改成功,新邮箱为: <span class="c-red"> <strong id="newemail">{$newemail}</strong> </span> </p>
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-4 col-sm-4 col-xs-offset-2 col-sm-offset-2">
                        <input type="button" class="btn btn-primary radius"  value="&nbsp;确&nbsp;&nbsp;定&nbsp;" onClick="modifyEmail();">
                    </div>
                </div>
            </div>
            {/eq}
        </div>
    </div>
</article>

<!--_footer 作为公共模版分离出去-->
{include file="common/_footer" /}
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">

//检查input是否为空
function checkEmpty(data,holder,msg){
    if(data.length <= 0){
        $(holder).html(msg);
        return false;
    }else{
        $(holder).html('');
        return true; 
    }
}

//验证原密码,邮箱
function checkPassword(){
    var password=$("#password").val();

    test=checkEmpty(password,'.pspan','密码不能为空');
    if(!test) return false;
    $test=$.post('modifypwd',{'password':password},function(data){
        if(data.status!=1){
            $('.pspan').html("* 密码不正确请重新输入");
            return false;
        }else{
            $('.pspan').html("");
            return true;
        }
    },'json');
    return test;
}

$("#password").change(function(){
    checkPassword();
});

function checkEmail(){
    var email=$("#email").val();

    test=checkEmpty(email,'.espan','邮箱不能为空');
    if(!test) return false;
    if(!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/)){
        $('.espan').html("* 邮箱格式不对,请重新输入");
        return false;
    }else{
        $test=$.post('getpwd',{'email':email},function(data){
                $('.espan').html(data.msg);
                return data.status;
        },'json');
        return test;
    }
}

$("#form-admin-email").submit(function(){
    var test=true; 
    test=checkPassword();
    if(!test) return false;
    test=checkEmail;
    if(!test) return false;
});


//提交验证码
function checkToken(){
    var token=$("#token").val();

    test=checkEmpty(token,'.tspan','验证码不能为空');
    if(!test) return false;
    test=token.match(/^\d{6}$/)
    if(!test){
        $('.tspan').html("* 验证码格式不对,请重新输入");
        return false;
    }else{
        $('.tspan').html("");
        return true;
    }
}

$("#form-admin-token").submit(function(){
    var test=true; 
    test=checkToken();
    if(!test) return false;
});


//修改密码
function modifyEmail(){
    var newemail=$("#newemail").text();
    window.parent.$("#email").html(newemail);
    layer_close()
}

</script>
<!--请在上方写此页面业务相关的脚本--> 
</body>
</html>